package com.kexio.config.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 配置管理属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.config")
public class ConfigProperties {
    
    /**
     * 是否启用配置管理
     */
    private boolean enabled = false;
    
    /**
     * 是否启用动态配置 (运行时修改)
     */
    private boolean dynamicConfig = true;
    
    /**
     * 是否启用版本控制
     */
    private boolean versionControl = true;
    
    /**
     * 默认环境
     */
    private String defaultEnvironment = "prod";
    
    /**
     * 字典配置
     */
    private DictConfig dict = new DictConfig();
    
    /**
     * 缓存配置
     */
    private CacheConfig cache = new CacheConfig();
    
    /**
     * 安全配置
     */
    private SecurityConfig security = new SecurityConfig();
    
    /**
     * 监控配置
     */
    private MonitorConfig monitor = new MonitorConfig();
    
    /**
     * 通知配置
     */
    private NotificationConfig notification = new NotificationConfig();
    
    public static class DictConfig {
        /**
         * 是否启用字典管理
         */
        private boolean enabled = true;
        
        /**
         * 缓存过期时间 (分钟)
         */
        private int cacheExpireMinutes = 30;
        
        /**
         * 是否预加载字典
         */
        private boolean preload = true;
        
        /**
         * 是否支持层级字典
         */
        private boolean hierarchical = true;
        
        /**
         * 默认字典类型前缀
         */
        private String defaultTypePrefix = "sys_";
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public int getCacheExpireMinutes() { return cacheExpireMinutes; }
        public void setCacheExpireMinutes(int cacheExpireMinutes) { this.cacheExpireMinutes = cacheExpireMinutes; }
        
        public boolean isPreload() { return preload; }
        public void setPreload(boolean preload) { this.preload = preload; }
        
        public boolean isHierarchical() { return hierarchical; }
        public void setHierarchical(boolean hierarchical) { this.hierarchical = hierarchical; }
        
        public String getDefaultTypePrefix() { return defaultTypePrefix; }
        public void setDefaultTypePrefix(String defaultTypePrefix) { this.defaultTypePrefix = defaultTypePrefix; }
    }
    
    public static class CacheConfig {
        /**
         * 是否启用本地缓存
         */
        private boolean localEnabled = true;
        
        /**
         * 是否启用Redis缓存
         */
        private boolean redisEnabled = true;
        
        /**
         * 本地缓存最大条目数
         */
        private int localMaxSize = 1000;
        
        /**
         * 本地缓存过期时间 (分钟)
         */
        private int localExpireMinutes = 10;
        
        /**
         * Redis缓存过期时间 (分钟)
         */
        private int redisExpireMinutes = 60;
        
        /**
         * 缓存键前缀
         */
        private String keyPrefix = "config:";
        
        // Getters and Setters
        public boolean isLocalEnabled() { return localEnabled; }
        public void setLocalEnabled(boolean localEnabled) { this.localEnabled = localEnabled; }
        
        public boolean isRedisEnabled() { return redisEnabled; }
        public void setRedisEnabled(boolean redisEnabled) { this.redisEnabled = redisEnabled; }
        
        public int getLocalMaxSize() { return localMaxSize; }
        public void setLocalMaxSize(int localMaxSize) { this.localMaxSize = localMaxSize; }
        
        public int getLocalExpireMinutes() { return localExpireMinutes; }
        public void setLocalExpireMinutes(int localExpireMinutes) { this.localExpireMinutes = localExpireMinutes; }
        
        public int getRedisExpireMinutes() { return redisExpireMinutes; }
        public void setRedisExpireMinutes(int redisExpireMinutes) { this.redisExpireMinutes = redisExpireMinutes; }
        
        public String getKeyPrefix() { return keyPrefix; }
        public void setKeyPrefix(String keyPrefix) { this.keyPrefix = keyPrefix; }
    }
    
    public static class SecurityConfig {
        /**
         * 是否加密敏感配置
         */
        private boolean encryptSensitive = true;
        
        /**
         * 是否审计配置变更
         */
        private boolean auditChanges = true;
        
        /**
         * 是否需要权限验证
         */
        private boolean requirePermission = true;
        
        /**
         * 加密密钥
         */
        private String encryptKey;
        
        /**
         * 加密算法
         */
        private String encryptAlgorithm = "AES";
        
        /**
         * 敏感配置关键字
         */
        private String[] sensitiveKeywords = {"password", "secret", "key", "token"};
        
        // Getters and Setters
        public boolean isEncryptSensitive() { return encryptSensitive; }
        public void setEncryptSensitive(boolean encryptSensitive) { this.encryptSensitive = encryptSensitive; }
        
        public boolean isAuditChanges() { return auditChanges; }
        public void setAuditChanges(boolean auditChanges) { this.auditChanges = auditChanges; }
        
        public boolean isRequirePermission() { return requirePermission; }
        public void setRequirePermission(boolean requirePermission) { this.requirePermission = requirePermission; }
        
        public String getEncryptKey() { return encryptKey; }
        public void setEncryptKey(String encryptKey) { this.encryptKey = encryptKey; }
        
        public String getEncryptAlgorithm() { return encryptAlgorithm; }
        public void setEncryptAlgorithm(String encryptAlgorithm) { this.encryptAlgorithm = encryptAlgorithm; }
        
        public String[] getSensitiveKeywords() { return sensitiveKeywords; }
        public void setSensitiveKeywords(String[] sensitiveKeywords) { this.sensitiveKeywords = sensitiveKeywords; }
    }
    
    public static class MonitorConfig {
        /**
         * 是否启用监控
         */
        private boolean enabled = true;
        
        /**
         * 慢查询阈值 (毫秒)
         */
        private long slowQueryThreshold = 1000;
        
        /**
         * 统计时间窗口 (分钟)
         */
        private int statsWindow = 60;
        
        /**
         * 是否记录详细日志
         */
        private boolean detailedLog = false;
        
        /**
         * 是否启用性能指标
         */
        private boolean enableMetrics = true;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public long getSlowQueryThreshold() { return slowQueryThreshold; }
        public void setSlowQueryThreshold(long slowQueryThreshold) { this.slowQueryThreshold = slowQueryThreshold; }
        
        public int getStatsWindow() { return statsWindow; }
        public void setStatsWindow(int statsWindow) { this.statsWindow = statsWindow; }
        
        public boolean isDetailedLog() { return detailedLog; }
        public void setDetailedLog(boolean detailedLog) { this.detailedLog = detailedLog; }
        
        public boolean isEnableMetrics() { return enableMetrics; }
        public void setEnableMetrics(boolean enableMetrics) { this.enableMetrics = enableMetrics; }
    }
    
    public static class NotificationConfig {
        /**
         * 是否启用配置变更通知
         */
        private boolean enabled = false;
        
        /**
         * 通知方式 (email, sms, webhook)
         */
        private String[] methods = {"email"};
        
        /**
         * 通知接收人
         */
        private String[] recipients = {};
        
        /**
         * Webhook地址
         */
        private String webhookUrl;
        
        /**
         * 是否异步通知
         */
        private boolean async = true;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String[] getMethods() { return methods; }
        public void setMethods(String[] methods) { this.methods = methods; }
        
        public String[] getRecipients() { return recipients; }
        public void setRecipients(String[] recipients) { this.recipients = recipients; }
        
        public String getWebhookUrl() { return webhookUrl; }
        public void setWebhookUrl(String webhookUrl) { this.webhookUrl = webhookUrl; }
        
        public boolean isAsync() { return async; }
        public void setAsync(boolean async) { this.async = async; }
    }
    
    // Main class getters and setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public boolean isDynamicConfig() { return dynamicConfig; }
    public void setDynamicConfig(boolean dynamicConfig) { this.dynamicConfig = dynamicConfig; }
    
    public boolean isVersionControl() { return versionControl; }
    public void setVersionControl(boolean versionControl) { this.versionControl = versionControl; }
    
    public String getDefaultEnvironment() { return defaultEnvironment; }
    public void setDefaultEnvironment(String defaultEnvironment) { this.defaultEnvironment = defaultEnvironment; }
    
    public DictConfig getDict() { return dict; }
    public void setDict(DictConfig dict) { this.dict = dict; }
    
    public CacheConfig getCache() { return cache; }
    public void setCache(CacheConfig cache) { this.cache = cache; }
    
    public SecurityConfig getSecurity() { return security; }
    public void setSecurity(SecurityConfig security) { this.security = security; }
    
    public MonitorConfig getMonitor() { return monitor; }
    public void setMonitor(MonitorConfig monitor) { this.monitor = monitor; }
    
    public NotificationConfig getNotification() { return notification; }
    public void setNotification(NotificationConfig notification) { this.notification = notification; }
}
